package cqgans.app.sunao.com.cqgans.ui;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import cqgans.app.sunao.com.cqgans.common.AppConstant;
import cqgans.app.sunao.com.cqgansnew.R;

import static cqgans.app.sunao.com.cqgans.common.AppConstant.isCom;

/**
 * Created by sunao on 2017/6/12.
 */
@SuppressWarnings("WrongConstant")
@ContentView(R.layout.activity_home2)
public class Home2Activity extends BaseActivity  {



    @ViewInject(R.id.user_product_btn)
    private Button user_product_btn;
    @ViewInject(R.id.com_product_btn)
    private Button com_product_btn;

    @ViewInject(R.id.change_pass_btn)
    private Button change_pass_btn;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);


    }

    @Override
    protected void onResume() {
        super.onResume();
        setTitleBar("安燃通", 3);
        sharedPreferences = getSharedPreferences("cqgas", Context.MODE_PRIVATE);

        initLayout();

    }

    private void initLayout() {

        user_product_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isCom = false;
                startActivity(new Intent(Home2Activity.this, ProductActivity.class));
            }
        });
        com_product_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isCom = true;
                startActivity(new Intent(Home2Activity.this, ProductActivity.class));
            }
        });
        change_pass_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(Home2Activity.this, ChangePwdActivity.class));

            }
        });
        TextView close = (TextView) this.findViewById(R.id.close);
        close.setVisibility(View.VISIBLE);
        close.setText("切换账号");
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AppConstant.user = null;
                editor = sharedPreferences.edit();//获取编辑器
                editor.putInt("id", 0);
                editor.commit();
                startActivity(new Intent(Home2Activity.this, MainActivity.class));
                finish();
            }
        });
        findViewById(R.id.user).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AppConstant.TARGET_URL = AppConstant.JSS_ACCOUNT_URL;
                startActivity(new Intent(Home2Activity.this, WebActivity.class));
            }
        });
        findViewById(R.id.user_ll).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    AppConstant.TARGET_URL = AppConstant.JSS_ACCOUNT_URL;
                    startActivity(new Intent(Home2Activity.this, WebActivity.class));

            }
        });
    }


}
